//
//  CHSimpleViewController.swift
//  PubPodsSdkDemo
//
//  Created by cyptt on 2023/3/30.
//

import UIKit
class CHSimpleListViewController: UIViewController {

    @IBOutlet weak var nextBtn: UIButton!
    var dataSources:[CHSimpleListModel] = []
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.white
        self.view.addSubview(self.listView)
      
        
 
        
       
       
        
        
        //异步情况暂时未用
       
        
        
        for i in 0..<30{
            
            let model = CHSimpleListModel()
            model.lineLeftW = 20
            model.lineRightW = 20
            model.lineIsRight = true
            
            model.leftTitle = "第" + String(i)
       
            if i < 1{
                model.rightImage = UIImage.init(named: "arrow_down_icon")
                model.leftImage = UIImage.init(named: "juanxin_icon")

                model.cellType = .ALL
            }
            else if i < 3{
                model.cellType = .CENTER_ONLY

            }else if i < 5{
                model.cellType = .L_ALL
            }else if i < 7{
                model.rightImage = UIImage.init(named: "arrow_down_icon")
                model.cellType = .L_ALL_R_IMG
            }else if i < 9{
                model.leftTitle = "左边的"
                model.cellType = .L_ALL_R_ALL
            }else if i < 11{

                model.cellType = .L_ALL_R_Title
            }else if i < 13{

                model.cellType = .L_Title_R_ALL
                model.cellHigh = 100
            }else if i < 15{
                model.cellType = .L_Title_R_IMG
            }else if i < 17{
                model.cellType = .L_Title_R_Title
            }else if i < 19{
                model.cellType = .L_Title_R_IMG_IMG
            }else if i < 21{
                model.cellType = .L_Title_R_Input

            }else if i < 23{
                model.cellType = .L_ALL_R_Input
            }else{
                model.cellType = .L_Title
            }
            
            
//            model.cellType = .L_Title_R_IMG_IMG
    
    
            model.cellHandelr = { cell in
//                cell?.layer.backgroundColor = UIColor.white.cgColor
                cell?.layer.cornerRadius = 13
                cell?.layer.masksToBounds = true
    
            }

            dataSources.append(model)
        }
        
        
        
        self.listView.setDataSource(listModels: dataSources)

        self.listView.cellItemClickCallBack { index, simpleModel in
            
            if index == 18{
                print("ddd")
               
                simpleModel?.rightImage2 = UIImage.init(named: "juanxin_icon")
                self.listView.freshItem(index: 18, listModel: simpleModel!)
            }
        }
        
        self.listView.cellInputResultCallBack { text, index, simpleModel in
            print(text)
        }
        
        self.listView.spaceTabHeaderH = 30
        self.listView.spaceTabFootH = 50

        self.listView.snp.makeConstraints { make in
            make.width.equalToSuperview()
            make.bottom.equalTo(-100)
            make.left.equalTo(0)
            make.top.equalTo(0)
        }
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let model:CHSimpleListModel = CHSimpleListModel()
        model.leftTitle = "姓名"
        model.rightTitle = "里斯"
        self.listView.freshItem(index: 0, listModel: model)
    }
    lazy var listView = {()-> CHSimpleListView in
//        let view:CHSimpleListView = CHSimpleListView.init(rowMaxCount: 4, itemSpacing: 16, lineSpacing: 14)
        let view:CHSimpleListView  = CHSimpleListView.init()
        view.backgroundColor = UIColor.white

        return view
    }()

    @IBAction func btnClick(_ sender: UIButton) {
        
        print("点击了")
        
        let model:CHSimpleListModel = self.dataSources[18]
        print(model)
        print(model.rightText)
        
    }
    
    
    

}
